#include "eventwindow.h"
#include <QDebug>

EventWindow::EventWindow(QWidget *parent) : QWidget(parent)
{
    resize(800,600);
    setMouseTracking(true);

    startButton = new QPushButton("启动",this);
    endButton = new QPushButton("停止",this);

#if 0
    gifLabel = new QLabel(this);

    gifLabel->move(100,100);
    QMovie *movie = new QMovie(":/new/prefix1/img/dancer.gif");
    gifLabel->setMovie(movie);
    movie->start();
#endif
    endButton->move(100,0);
    connect(startButton,&QPushButton::clicked,this,&EventWindow::startTime);
    connect(endButton,&QPushButton::clicked,this,&EventWindow::killTime);
}

void EventWindow::mousePressEvent(QMouseEvent *event)
{
    if(event->button() == Qt::RightButton)
        this->close();
}

void EventWindow::mouseMoveEvent(QMouseEvent *event)
{
    qDebug()<<"move"<<event->globalPos();
}

void EventWindow::keyPressEvent(QKeyEvent *event)
{
    //if(event->key() == Qt::Key_Escape)
    if(event->key() == Qt::Key_Return)
        close();
}

void EventWindow::timerEvent(QTimerEvent *event)
{
    qDebug()<<"timer";
}

bool EventWindow::event(QEvent *event)
{
    if(event->type() == QEvent::HoverEnter)
    {
        qDebug()<<"hover enter";
    }
    return true;
}

void EventWindow::startTime()
{
    timeId = startTimer(1000);
}

void EventWindow::killTime()
{
    killTimer(timeId);
    qDebug()<<"the timerEvent is been killed";
}
